package com.soft.base.spring.util;


import org.springframework.util.StringUtils;

import javax.servlet.http.HttpSession;
import java.io.Serializable;

/**
 * class
 *
 * @author user
 * @date 2020/06/05
 */
public class Session {

    public static final void set(String name, Serializable value) {
        Request.request().getSession().setAttribute(name, (Serializable)value);
    }

    public static final void unset(String name) {
        Request.request().getSession().removeAttribute(name);
    }

    public static final Object get(String name) {
        return Request.request().getSession().getAttribute(name);
    }

    public static final Integer getInt(String name, Integer defaultValue) {
        Object value = get(name);
        if (value instanceof Integer) {
            return (Integer) value;
        }
        if (value instanceof String) {
            if (!StringUtils.isEmpty(value)) {
                return Integer.valueOf((String) value);
            }
        }
        return defaultValue;
    }

}
